﻿using AutoMapper;
using Harmontronics.Model.Dto;
using Harmontronics.Model.Dto.Menu;
using Harmontronics.Model.Dto.Model;
using Harmontronics.Model.Dto.Role;
using Harmontronics.Model.Dto.User;
using Harmontronics.Model.Entitys;
using SqlSugar;

namespace Harmontronics.Api.Config
{
    /// <summary>
    /// Dto的映射配置
    /// </summary>
    public class AutoMapperConfigs : Profile
    {
        public AutoMapperConfigs()
        {
            //角色
            CreateMap<Role, RoleRes>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<Role, RoleReq>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<RoleAdd, Role>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<RoleEdit, Role>()
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateBy, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            //用户
            CreateMap<Users, UserRes>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<Users, UserReq>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<UserAdd, Users>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<UserEdit, Users>()
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForMember(dest => dest.CreateBy, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            //菜单
            CreateMap<Menu, MenuRes>(
                ).ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<MenuAdd, Menu>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<MenuEdit, Menu>()
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            //工厂
            CreateMap<WorkShopModel, WorkShop>();
            CreateMap<WorkShop, WorkShop>();
            CreateMap<WorkShop, WorkShopModel>();
            //产线
            CreateMap<ProductionLine, ProductionLine>();
            CreateMap<ProductionLineModel, ProductionLine>()
                .ForMember(dest => dest.WorkShopId, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            CreateMap<ProductionLine, ProductionLineModel>()
                .ForMember(dest => dest.workShop, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            //plc
            CreateMap<PlcSetting, PlcSettingModel>();
            CreateMap<PlcSettingModel, PlcSetting>();
            //station
            CreateMap<Station, StationModel>()
                .ForMember(dest => dest.PlcSetting, opt => opt.Ignore())
                .ForMember(dest => dest.ProductionLine, opt => opt.Ignore());
            CreateMap<Station, Station>();
            //process
            CreateMap<Process, ProcessModel>()
                .ForMember(dest => dest.WorkStation, opt => opt.Ignore());
            CreateMap<Process, Process>();
            //RecipeConfig
            CreateMap<RecipeConfig, RecipeConfigModel>()
                .ForMember(dest => dest.RecipeType, opt => opt.Ignore());
            CreateMap<RecipeConfigModel, RecipeConfig>()
                .ForMember(dest => dest.RecipeTypeId, opt => opt.Ignore());
            CreateMap<RecipeConfig, RecipeConfig>();
            //Recipe 
            CreateMap<Recipe, RecipeModel>()
                .ForMember(dest => dest.RecipeType, opt => opt.Ignore());
            CreateMap<RecipeModel, Recipe>()
                .ForMember(dest => dest.RecipeTypeId, opt => opt.Ignore());
            CreateMap<Recipe, Recipe>();
            //UserRecipe 
            CreateMap<UserRecipe, UserRecipeModel>()
                .ForMember(dest => dest.RecipeConfig, opt => opt.Ignore());
            CreateMap<UserRecipeModel, UserRecipe>()
                .ForMember(dest => dest.ParameterId, opt => opt.Ignore());
            CreateMap<UserRecipe, UserRecipe>();
            //Part 
            CreateMap<Part, PartModel>()
                .ForMember(dest => dest.Recipe, opt => opt.Ignore());
            CreateMap<PartModel, Part>()
                .ForMember(dest => dest.RecipeId, opt => opt.Ignore());
            CreateMap<PartEdit, Part>();
            CreateMap<Part, PartEdit>();
            CreateMap<Part, Part>(); 
            //Material 
            CreateMap<Material, MaterialModel>();
            CreateMap<MaterialModel, Material>();
            CreateMap<Material, Material>();
            CreateMap<MaterialEdit, Material>()
                .ForMember(dest => dest.CreateTime, opt => opt.Ignore())
                .ForAllMembers(opt => opt.Condition((src, dest, sourceMember) => sourceMember != null));
            //RecipeType
            CreateMap<RecipeType, RecipeTypeModel>();
            CreateMap<RecipeTypeModel, RecipeType>();
            CreateMap<RecipeType, RecipeType>();
        }
    }
}
